# -*- encoding=utf8 -*-
__author__ = "lushunming"

from airtest.core.api import *

auto_setup(__file__)
wake()
stop_app("com.eg.android.AlipayGphone")
start_app("com.eg.android.AlipayGphone", "AlipayLogin")
touch(Template(r"tpl1611122832553.png", record_pos=(0.194, -0.269), resolution=(1080, 2400)))

while True:
    swipe(Template(r"tpl1611126271430.png", record_pos=(0.344, 0.787), resolution=(1080, 2400)), vector=[-2, -2])
    if exists(Template(r"tpl1611122987714.png", record_pos=(0.001, 0.537), resolution=(1080, 2400))):
        touch(Template(r"tpl1611122987714.png", record_pos=(0.001, 0.537), resolution=(1080, 2400)))
        swipe(Template(r"tpl1611127850397.png", record_pos=(-0.229, -0.846), resolution=(1080, 2400)),
              vector=[-0.1, -0.1])
        while True:
            persons = find_all(Template(r"tpl1611129065899.png", record_pos=(-0.193, 0.226), resolution=(1080, 2400)))
            for person in persons:
                wait(Template(r"tpl1611127850397.png", record_pos=(-0.229, -0.846), resolution=(1080, 2400)))
                touch(person['result'])
                if exists(Template(r"tpl1611129337618.png", record_pos=(0.42, -0.684), resolution=(1080, 2400))):

                    if exists(Template(r"tpl1611122765241.png", record_pos=(0.349, -0.347), resolution=(1080, 2400))):
                        balls = find_all(
                            Template(r"tpl1611122765241.png", record_pos=(0.349, -0.347), resolution=(1080, 2400)))
                        for ball in balls:
                            touch(ball['result'])
                        keyevent("BACK")
                    keyevent("BACK")
            if exists(Template(r"tpl1611128294338.png", record_pos=(0.001, 0.944), resolution=(1080, 2400))):
                break
            swipe(Template(r"tpl1611127850397.png", record_pos=(-0.229, -0.846), resolution=(1080, 2400)),
                  vector=[-1, -1])
